#!/bin/bash

# --------------------------------------------------------------------
#Script to aid in packaging of Mac OSX EMS Client for Dragon 7
#  Copyright (C) 2008  Joel Parker
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
# --------------------------------------------------------------------
#Original Author:  Joel Parker
#Release Date:  2/14/2008

if [ ! -e ./linux-client/EmsClient_Linux*.tar.gz ]; then
	echo "Attempting to Copy EMS Linux Client from Downloads Directory"
	cp -v ~/Downloads/EmsClient_Linux*.tar.gz ./linux-client/ ;
	if [ $? -ne 0 ]; then
		echo "Error copying Linux Client Installer.  QUIT"
		exit;
	fi
else
	echo "Linux EMS Client Appears to already be in linux-client directory."
fi

HOME=`pwd`;
cd linux-client/;
echo "Expanding Linux EMS Client Installer"
tar -zxf EmsClient_Linux*.tar.gz
cd EMS-client/Disk1/InstData/

unzip Resource1.zip 2>&1 > /dev/null
#Nicer to work with without dollar sign
mv \$IA_PROJECT_DIR\$/ IA_PROJECT_DIR
cd IA_PROJECT_DIR/
pwd

#Move All Jars expect swt.jar
echo "Moving Jar files";
for i in `find . -type f -name *.jar | grep -v "swt.jar"`; do 
  mv -f "$i" "$HOME/jars/"; 
done

#Move enterasys log to images/images
echo "Moving Enterasys Logo";
find . -type f -name enterasysLogo.gif | xargs -I{} mv -f "{}" "$HOME/images/images"

#Move All other files
echo "Moving other files";
for i in `find . -type f | grep -v swt`; do 
mv -f "$i" "$HOME/other/" ; 
done

cd "$HOME"
mv jars/icons_zg_ia_sf.jar images/icons/
mv jars/images_zg_ia_sf.jar images/images/
cd images/icons/
echo "Moving Client icons into place"
jar -xf icons_zg_ia_sf.jar && rm -f icons_zg_ia_sf.jar
cd ../images
echo "Moving Client images into place"
jar -xf images_zg_ia_sf.jar && rm -f images_zg_ia_sf.jar

cd "$HOME"
echo "Using Mac OSX swt jar for client"
cp -f swt.jar jars/

echo "READY!  Time to run ant"
ant
open .
